function allSort(costs){
    return costs.sort((a,b)=>b[1]-b[0]-a[1]+a[0]).reduce((count,val,index)=>count+val[index<costs.length/2?0:1],0)
}
// 示例
const costs=[[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]
console.log(allSort(costs));